//
//  LGCareSelectTemplateView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/30.
//  照护计划 -- 模版导入 -- 选择模版

#import "LGCareSelectTemplateView.h"

@interface LGCareSelectTemplateView()
/**   */
@property (nonatomic , strong)LGCareTemplateTypeView *interveneView;
/**   */
@property (nonatomic , strong)LGCareTemplateTypeView *medicineView;

@end

@implementation LGCareSelectTemplateView

-(instancetype)initWithTitle:(NSString *)title baseHeight:(CGFloat)baseHeight{
    self = [super initWithTitle:title baseHeight:baseHeight];
    if (self) {
        [self.baseView addSubview:self.interveneView];
        [self.baseView addSubview:self.medicineView];
    }
    return self;
}

-(void)setCurrentType:(NSString *)currentType{
    _currentType = currentType;
    self.interveneView.selected = NO;
    self.medicineView.selected = NO;
    if ([currentType isEqualToString:@"1"]||[currentType isEqualToString:@"2"]||[currentType isEqualToString:@"3"]) {
        self.interveneView.selected = YES;
    }else if ([currentType isEqualToString:@"4"]){
        self.medicineView.selected = YES;
    }
}

-(void)actionButtonTouched:(UIButton *)sender{
    NSString *type = (sender == self.interveneView.actionBtn)?@"intervene":@"medicine";
    if (self.importTemplateType) {
        self.importTemplateType(type);
    }
    [self hiddenViewAnmation];
}

-(LGCareTemplateTypeView *)interveneView{
    if(!_interveneView){
        _interveneView = [[LGCareTemplateTypeView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(60), Screen_W-viewPix(32), viewPix(103))];
        [_interveneView.actionBtn addTarget:self action:@selector(actionButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
        _interveneView.type = @"intervene";
    }
    return _interveneView;
}

-(LGCareTemplateTypeView *)medicineView{
    if(!_medicineView){
        _medicineView = [[LGCareTemplateTypeView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.interveneView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(103))];
        [_medicineView.actionBtn addTarget:self action:@selector(actionButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
        _medicineView.type = @"medicine";
    }
    return _medicineView;
}


@end


#pragma mark
#pragma mark ====> LGCareTemplateTypeView
@interface LGCareTemplateTypeView()
/**   */
@property (nonatomic , strong)UIImageView *bgImageView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGCareTemplateTypeView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if ([type isEqualToString:@"intervene"]) {
        //介入治疗
        self.iconView.image = [UIImage imageNamed:@"模版导入-介入治疗"];
        self.titleLabel.text = @"房颤介入治疗";
        self.contentLabel.text = @"房颤射频消融术后、左心耳封堵术后居家康复";
    }else{
        //药物治疗
        self.iconView.image = [UIImage imageNamed:@"模版导入-药物治疗"];
        self.titleLabel.text = @"房颤药物治疗";
        self.contentLabel.text = @"房颤药物治疗居家康复";
    }
}

-(void)setSelected:(BOOL)selected{
    _selected = selected;
    self.bgImageView.hidden = !selected;
    self.tipLabel.hidden = !selected;
    self.tipView.hidden = !selected;
    NSString *borderColor = (selected == YES)?@"":@"#E6E6E6";
    NSString *titleColor = (selected == YES)?@"#FFFFFF":@"#282828";
    NSString *contentColor = (selected == YES)?@"#FFFFFF":@"#909399";
    self.titleLabel.textColor = [UIColor colorWithString:titleColor];
    self.contentLabel.textColor = [UIColor colorWithString:contentColor];
    self.layer.borderColor = [UIColor colorWithString:borderColor].CGColor;
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addBorder:@"#E6E6E6" lineWidth:1.5 cornerRidus:10];
    [self addSubview:self.bgImageView];
    [self addSubview:self.iconView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.tipLabel];
    [self addSubview:self.tipView];
    [self addSubview:self.contentLabel];
    [self addSubview:self.actionBtn];
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self).offset(-viewPix(72));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(12));
        make.centerY.equalTo(self.titleLabel);
        make.width.height.equalTo(@(viewPix(12)));
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left);
        make.centerY.equalTo(self.tipView);
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    }
    return _actionBtn;
}

-(UIImageView *)bgImageView{
    if(!_bgImageView){
        _bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"模版导入-当前背景"]];
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageView.hidden = YES;
    }
    return _bgImageView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"模版导入-介入治疗"]];
        _iconView.frame = CGRectMake(viewPix(16), viewPix(31), viewPix(40), viewPix(40));
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(70), viewPix(16), viewPix(130), viewPix(25));
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _contentLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"进行中" colorString:@"#606266" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _tipLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _tipView;
}

@end
